<html>
<head>
<title>addCustomer.py</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.s0 { color: #75715e;}
.s1 { color: #f8f8f2;}
.s2 { color: #66d9ef; font-style: italic;}
.s3 { color: #f92672;}
.s4 { color: #e6db74;}
.s5 { color: #ae81ff;}
.ln { color: #f8f8f2; font-weight: normal; font-style: normal; }
</style>
</head>
<body bgcolor="#272822">
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#606060" >
<tr><td><center>
<font face="Arial, Helvetica" color="#000000">
addCustomer.py</font>
</center></td></tr></table>
<pre><a name="l1"><span class="ln">1    </span></a><span class="s0"># !/usr/bin/python3</span>
<a name="l2"><span class="ln">2    </span></a><span class="s0"># -*- coding: utf-8 -*-</span>
<a name="l3"><span class="ln">3    </span></a><span class="s0">&quot;&quot;&quot; 
<a name="l4"><span class="ln">4    </span></a>@File Name  : addCustomer.py 
<a name="l5"><span class="ln">5    </span></a>@Author     : LeeCQ 
<a name="l6"><span class="ln">6    </span></a>@Date-Time  : 2020/8/29 11:19 
<a name="l7"><span class="ln">7    </span></a> 
<a name="l8"><span class="ln">8    </span></a>添加用户 
<a name="l9"><span class="ln">9    </span></a>&quot;&quot;&quot;</span>
<a name="l10"><span class="ln">10   </span></a><span class="s2">import </span><span class="s1">time</span>
<a name="l11"><span class="ln">11   </span></a>
<a name="l12"><span class="ln">12   </span></a><span class="s2">from </span><span class="s1">common </span><span class="s2">import </span><span class="s3">*</span>
<a name="l13"><span class="ln">13   </span></a><span class="s2">from </span><span class="s1">login </span><span class="s2">import </span><span class="s1">login_easy, login</span>
<a name="l14"><span class="ln">14   </span></a><span class="s2">from </span><span class="s1">selenium.webdriver.common.action_chains </span><span class="s2">import </span><span class="s1">ActionChains</span>
<a name="l15"><span class="ln">15   </span></a><span class="s2">from </span><span class="s1">selenium.webdriver.common.keys </span><span class="s2">import </span><span class="s1">Keys</span>
<a name="l16"><span class="ln">16   </span></a><span class="s2">import </span><span class="s1">unittest</span>
<a name="l17"><span class="ln">17   </span></a>
<a name="l18"><span class="ln">18   </span></a><span class="s1">u_p </span><span class="s3">= </span><span class="s1">(</span><span class="s4">'test'</span><span class="s1">, </span><span class="s4">'123456'</span><span class="s1">)</span>
<a name="l19"><span class="ln">19   </span></a>
<a name="l20"><span class="ln">20   </span></a>
<a name="l21"><span class="ln">21   </span></a><span class="s2">def </span><span class="s1">e(q, w)</span><span class="s3">:</span>
<a name="l22"><span class="ln">22   </span></a>    <span class="s0">&quot;&quot;&quot;交互式提示符快捷启动&quot;&quot;&quot;</span>
<a name="l23"><span class="ln">23   </span></a>    <span class="s2">return </span><span class="s1">AddCustomer(login_easy(</span><span class="s3">*</span><span class="s1">u_p), q, w)</span>
<a name="l24"><span class="ln">24   </span></a>
<a name="l25"><span class="ln">25   </span></a>
<a name="l26"><span class="ln">26   </span></a><span class="s2">class </span><span class="s1">TestAddCustoms(unittest.TestCase)</span><span class="s3">:</span>
<a name="l27"><span class="ln">27   </span></a>    <span class="s0">&quot;&quot;&quot;&quot;&quot;&quot;</span>
<a name="l28"><span class="ln">28   </span></a>
<a name="l29"><span class="ln">29   </span></a>    <span class="s2">def </span><span class="s1">setUp(self) -&gt; </span><span class="s2">None</span><span class="s3">:</span>
<a name="l30"><span class="ln">30   </span></a>        <span class="s1">self.driver </span><span class="s3">= </span><span class="s1">login_easy(</span><span class="s4">'test'</span><span class="s1">, </span><span class="s4">'123456'</span><span class="s1">)</span>
<a name="l31"><span class="ln">31   </span></a>        <span class="s1">self.name </span><span class="s3">= </span><span class="s4">'auto_02'</span>
<a name="l32"><span class="ln">32   </span></a>        <span class="s1">self._id </span><span class="s3">= </span><span class="s4">'auto_02'</span>
<a name="l33"><span class="ln">33   </span></a>
<a name="l34"><span class="ln">34   </span></a>    <span class="s2">def </span><span class="s1">tearDown(self) -&gt; </span><span class="s2">None</span><span class="s3">:</span>
<a name="l35"><span class="ln">35   </span></a>        <span class="s1">self.driver.close()</span>
<a name="l36"><span class="ln">36   </span></a>
<a name="l37"><span class="ln">37   </span></a>    <span class="s2">def </span><span class="s1">test_addCustomer(self)</span><span class="s3">:</span>
<a name="l38"><span class="ln">38   </span></a>        <span class="s1">d </span><span class="s3">= </span><span class="s1">AddCustomer(self.driver, self.name, self._id).driver</span>
<a name="l39"><span class="ln">39   </span></a>        <span class="s1">d.find_element_by_id(</span><span class="s4">'replace'</span><span class="s1">).click()</span>
<a name="l40"><span class="ln">40   </span></a>        <span class="s1">time.sleep(</span><span class="s5">2</span><span class="s1">)</span>
<a name="l41"><span class="ln">41   </span></a>        <span class="s1">trs </span><span class="s3">= </span><span class="s1">d.find_elements_by_css_selector(</span><span class="s4">'table#gridTable_frozen &gt; tbody &gt; tr'</span><span class="s1">)</span>
<a name="l42"><span class="ln">42   </span></a>        <span class="s1">names </span><span class="s3">= </span><span class="s1">[i.find_element_by_css_selector(</span><span class="s4">'td:nth-child(7)'</span><span class="s1">).get_attribute(</span><span class="s4">'title'</span><span class="s1">) </span><span class="s2">for </span><span class="s1">i </span><span class="s2">in </span><span class="s1">trs]</span>
<a name="l43"><span class="ln">43   </span></a>        <span class="s1">self.assertIn(self.name, names, </span><span class="s4">'添加客户档案成功!'</span><span class="s1">)</span>
<a name="l44"><span class="ln">44   </span></a>
<a name="l45"><span class="ln">45   </span></a>
<a name="l46"><span class="ln">46   </span></a><span class="s2">class </span><span class="s1">AddCustomer</span><span class="s3">:</span>
<a name="l47"><span class="ln">47   </span></a>    <span class="s1">iframe_tag </span><span class="s3">= </span><span class="s4">'iframe402881d260d3d2e90160d4468ae00003'</span>
<a name="l48"><span class="ln">48   </span></a>    <span class="s1">iframe_add </span><span class="s3">= </span><span class="s4">'CustomerFrom2'</span>
<a name="l49"><span class="ln">49   </span></a>
<a name="l50"><span class="ln">50   </span></a>    <span class="s2">def </span><span class="s1">__init__(self, _driver</span><span class="s3">: </span><span class="s1">BaseWebDriver, name, pact_id,</span>
<a name="l51"><span class="ln">51   </span></a>                 <span class="s1">city</span><span class="s3">=</span><span class="s4">'西安'</span><span class="s1">, contact</span><span class="s3">=</span><span class="s4">'LeeCQ'</span><span class="s1">, addr</span><span class="s3">=</span><span class="s4">'陕西省汉中市南郑区'</span><span class="s1">,</span>
<a name="l52"><span class="ln">52   </span></a>                 <span class="s1">detailed_addr</span><span class="s3">=</span><span class="s4">'Auto'</span><span class="s1">, start</span><span class="s3">=</span><span class="s4">'2009-8-9'</span><span class="s1">, end</span><span class="s3">=</span><span class="s4">'2020-9-8'</span><span class="s1">,</span>
<a name="l53"><span class="ln">53   </span></a>                 <span class="s1">company</span><span class="s3">=</span><span class="s4">'自动化注册公司'</span><span class="s1">, phone_num</span><span class="s3">=</span><span class="s4">'19011112222'</span>
<a name="l54"><span class="ln">54   </span></a>                 <span class="s1">)</span><span class="s3">:</span>
<a name="l55"><span class="ln">55   </span></a>        <span class="s1">self.d </span><span class="s3">= </span><span class="s1">_driver</span>
<a name="l56"><span class="ln">56   </span></a>        <span class="s1">self.d.implicitly_wait(</span><span class="s5">8</span><span class="s1">)</span>
<a name="l57"><span class="ln">57   </span></a>        <span class="s1">self.login()  </span><span class="s0"># 登录</span>
<a name="l58"><span class="ln">58   </span></a>        <span class="s1">self.open_customer_page()  </span><span class="s0"># 打开并切换到标签</span>
<a name="l59"><span class="ln">59   </span></a>        <span class="s1">self.add_customer()  </span><span class="s0"># 打开新增客户资料的页面，两次框架跳转</span>
<a name="l60"><span class="ln">60   </span></a>
<a name="l61"><span class="ln">61   </span></a>        <span class="s1">self.set_company(company)  </span><span class="s0"># 设置公司名</span>
<a name="l62"><span class="ln">62   </span></a>        <span class="s1">self.set_name(name)  </span><span class="s0"># 设置客户名</span>
<a name="l63"><span class="ln">63   </span></a>        <span class="s1">self.set_pact_id(pact_id)  </span><span class="s0"># 设置ID</span>
<a name="l64"><span class="ln">64   </span></a>        <span class="s1">self.set_clearing_from()  </span><span class="s0"># 结算方式</span>
<a name="l65"><span class="ln">65   </span></a>        <span class="s1">self.set_pact_time(start, end)  </span><span class="s0"># 设置时间</span>
<a name="l66"><span class="ln">66   </span></a>        <span class="s1">self.set_city(city)  </span><span class="s0"># 设置城市</span>
<a name="l67"><span class="ln">67   </span></a>        <span class="s1">self.set_contact(contact)  </span><span class="s0"># 设置联系人</span>
<a name="l68"><span class="ln">68   </span></a>        <span class="s1">self.set_addr(addr)  </span><span class="s0"># 设置发货地址</span>
<a name="l69"><span class="ln">69   </span></a>        <span class="s1">self.set_detailed_addr(detailed_addr)  </span><span class="s0"># 设置详细地址</span>
<a name="l70"><span class="ln">70   </span></a>        <span class="s1">self.set_phone_num(phone_num)  </span><span class="s0"># 设置电话号码</span>
<a name="l71"><span class="ln">71   </span></a>        <span class="s1">self.ok()</span>
<a name="l72"><span class="ln">72   </span></a>        <span class="s2">if </span><span class="s1">__name__ </span><span class="s3">== </span><span class="s4">'__main__'</span><span class="s3">:</span>
<a name="l73"><span class="ln">73   </span></a>            <span class="s1">time.sleep(</span><span class="s5">5</span><span class="s1">)</span>
<a name="l74"><span class="ln">74   </span></a>
<a name="l75"><span class="ln">75   </span></a>    <span class="s3">@</span><span class="s1">property</span>
<a name="l76"><span class="ln">76   </span></a>    <span class="s2">def </span><span class="s1">driver(self)</span><span class="s3">:</span>
<a name="l77"><span class="ln">77   </span></a>        <span class="s1">self.d.switch_to.default_content()</span>
<a name="l78"><span class="ln">78   </span></a>        <span class="s1">self.d.switch_to.frame(self.iframe_tag)</span>
<a name="l79"><span class="ln">79   </span></a>        <span class="s2">return </span><span class="s1">self.d</span>
<a name="l80"><span class="ln">80   </span></a>
<a name="l81"><span class="ln">81   </span></a>    <span class="s2">def </span><span class="s1">login(self)</span><span class="s3">:</span>
<a name="l82"><span class="ln">82   </span></a>        <span class="s0">&quot;&quot;&quot;判断登录，没登录自动登录&quot;&quot;&quot;</span>
<a name="l83"><span class="ln">83   </span></a>        <span class="s2">if </span><span class="s1">is_login(self.d) </span><span class="s2">is False</span><span class="s3">:</span>
<a name="l84"><span class="ln">84   </span></a>            <span class="s1">self.d </span><span class="s3">= </span><span class="s1">login(self.d, </span><span class="s4">'test'</span><span class="s1">, </span><span class="s4">'123456'</span><span class="s1">)</span>
<a name="l85"><span class="ln">85   </span></a>
<a name="l86"><span class="ln">86   </span></a>    <span class="s2">def </span><span class="s1">open_customer_page(self)</span><span class="s3">:</span>
<a name="l87"><span class="ln">87   </span></a>        <span class="s0">&quot;&quot;&quot;打开到标签&quot;&quot;&quot;</span>
<a name="l88"><span class="ln">88   </span></a>        <span class="s1">_d </span><span class="s3">= </span><span class="s1">self.d</span>
<a name="l89"><span class="ln">89   </span></a>        <span class="s1">ActionChains(_d).move_to_element(_d.find_element_by_id(</span><span class="s4">'402882b75ff3938e015ff396e33f0003'</span><span class="s1">)).perform()</span>
<a name="l90"><span class="ln">90   </span></a>        <span class="s1">time.sleep(</span><span class="s5">1</span><span class="s1">)</span>
<a name="l91"><span class="ln">91   </span></a>        <span class="s1">ActionChains(_d).move_to_element(_d.find_element_by_id(</span><span class="s4">'402881d260d3d2e90160d4468ae00003'</span><span class="s1">)).click().perform()</span>
<a name="l92"><span class="ln">92   </span></a>        <span class="s1">_d.switch_to.frame(self.iframe_tag)</span>
<a name="l93"><span class="ln">93   </span></a>        <span class="s1">self.d </span><span class="s3">= </span><span class="s1">_d</span>
<a name="l94"><span class="ln">94   </span></a>        <span class="s2">return </span><span class="s1">_d</span>
<a name="l95"><span class="ln">95   </span></a>
<a name="l96"><span class="ln">96   </span></a>    <span class="s2">def </span><span class="s1">add_customer(self, )</span><span class="s3">:</span>
<a name="l97"><span class="ln">97   </span></a>        <span class="s0">&quot;&quot;&quot;&quot;&quot;&quot;</span>
<a name="l98"><span class="ln">98   </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'customer-add'</span><span class="s1">).click()</span>
<a name="l99"><span class="ln">99   </span></a>        <span class="s1">self.d.switch_to.default_content()  </span><span class="s0"># 跳转到主框架</span>
<a name="l100"><span class="ln">100  </span></a>        <span class="s1">self.d.switch_to.frame(self.iframe_add)  </span><span class="s0"># 跳转到添加页面框架</span>
<a name="l101"><span class="ln">101  </span></a>        <span class="s2">return </span><span class="s1">self.d</span>
<a name="l102"><span class="ln">102  </span></a>
<a name="l103"><span class="ln">103  </span></a>    <span class="s2">def </span><span class="s1">set_company(self, company</span><span class="s3">=</span><span class="s4">'自动化注册公司'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l104"><span class="ln">104  </span></a>        <span class="s0">&quot;&quot;&quot;设置 所属注册公司&quot;&quot;&quot;</span>
<a name="l105"><span class="ln">105  </span></a>        <span class="s1">self.d.find_element_by_css_selector(</span><span class="s4">'#jcRegistration &gt; div'</span><span class="s1">).click()</span>
<a name="l106"><span class="ln">106  </span></a>        <span class="s1">tags </span><span class="s3">= </span><span class="s1">self.d.find_elements_by_css_selector(</span><span class="s4">'div#jcRegistration-option &gt; '</span>
<a name="l107"><span class="ln">107  </span></a>                                                    <span class="s4">'div.ui-select-option-content &gt; '</span>
<a name="l108"><span class="ln">108  </span></a>                                                    <span class="s4">'div.bbit-tree-bwrap &gt; '</span>
<a name="l109"><span class="ln">109  </span></a>                                                    <span class="s4">'div.bbit-tree-body &gt; ul &gt; li'</span>
<a name="l110"><span class="ln">110  </span></a>                                                    <span class="s1">)</span>
<a name="l111"><span class="ln">111  </span></a>        <span class="s2">for </span><span class="s1">_t </span><span class="s2">in </span><span class="s1">tags</span><span class="s3">:</span>
<a name="l112"><span class="ln">112  </span></a>            <span class="s1">_t_title </span><span class="s3">= </span><span class="s1">_t.find_element_by_tag_name(</span><span class="s4">'div'</span><span class="s1">).get_attribute(</span><span class="s4">'title'</span><span class="s1">)</span>
<a name="l113"><span class="ln">113  </span></a>            <span class="s2">if </span><span class="s1">_t_title </span><span class="s3">== </span><span class="s1">company</span><span class="s3">:</span>
<a name="l114"><span class="ln">114  </span></a>                <span class="s1">_t.click()</span>
<a name="l115"><span class="ln">115  </span></a>
<a name="l116"><span class="ln">116  </span></a>    <span class="s2">def </span><span class="s1">set_name(self, name</span><span class="s3">=</span><span class="s4">'AutoName'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l117"><span class="ln">117  </span></a>        <span class="s0">&quot;&quot;&quot;设置 客户名称&quot;&quot;&quot;</span>
<a name="l118"><span class="ln">118  </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'name'</span><span class="s1">).send_keys(name)</span>
<a name="l119"><span class="ln">119  </span></a>        <span class="s2">return </span><span class="s1">self.d</span>
<a name="l120"><span class="ln">120  </span></a>
<a name="l121"><span class="ln">121  </span></a>    <span class="s2">def </span><span class="s1">set_pact_id(self, _id</span><span class="s3">=</span><span class="s4">'Auto12321'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l122"><span class="ln">122  </span></a>        <span class="s0">&quot;&quot;&quot;设置合同ID&quot;&quot;&quot;</span>
<a name="l123"><span class="ln">123  </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'code'</span><span class="s1">).send_keys(_id)</span>
<a name="l124"><span class="ln">124  </span></a>        <span class="s2">return </span><span class="s1">self.d</span>
<a name="l125"><span class="ln">125  </span></a>
<a name="l126"><span class="ln">126  </span></a>    <span class="s2">def </span><span class="s1">set_clearing_from(self, clearer</span><span class="s3">=</span><span class="s4">'月结'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l127"><span class="ln">127  </span></a>        <span class="s0">&quot;&quot;&quot;设置结算方式&quot;&quot;&quot;</span>
<a name="l128"><span class="ln">128  </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'settlementType'</span><span class="s1">).click()</span>
<a name="l129"><span class="ln">129  </span></a>        <span class="s2">for </span><span class="s1">_clear </span><span class="s2">in </span><span class="s1">self.d.find_elements_by_css_selector(</span><span class="s4">'div#settlementType-option &gt; div &gt; ul &gt; li'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l130"><span class="ln">130  </span></a>            <span class="s2">if </span><span class="s1">_clear.text </span><span class="s3">== </span><span class="s1">clearer</span><span class="s3">:</span>
<a name="l131"><span class="ln">131  </span></a>                <span class="s1">_clear.click()</span>
<a name="l132"><span class="ln">132  </span></a>                <span class="s2">return </span><span class="s1">self.d</span>
<a name="l133"><span class="ln">133  </span></a>
<a name="l134"><span class="ln">134  </span></a>    <span class="s2">def </span><span class="s1">set_pact_time(self, start</span><span class="s3">=</span><span class="s4">'2020-7-21'</span><span class="s1">, end</span><span class="s3">=</span><span class="s4">'2021-06-29'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l135"><span class="ln">135  </span></a>        <span class="s0">&quot;&quot;&quot;设置合同开始时间&quot;&quot;&quot;</span>
<a name="l136"><span class="ln">136  </span></a>        <span class="s0"># self.d.find_element_by_id('startTime').click()</span>
<a name="l137"><span class="ln">137  </span></a>        <span class="s0"># self.d.switch_to.default_content()</span>
<a name="l138"><span class="ln">138  </span></a>        <span class="s0"># time.sleep(1)</span>
<a name="l139"><span class="ln">139  </span></a>        <span class="s0"># self.d.switch_to.frame(self.d.find_element_by_xpath('//iframe[@hidefocus=&quot;true&quot;]'))</span>
<a name="l140"><span class="ln">140  </span></a>        <span class="s0"># self._set_time(start)</span>
<a name="l141"><span class="ln">141  </span></a>        <span class="s1">self._set_times(</span><span class="s4">'startTime'</span><span class="s1">, start)</span>
<a name="l142"><span class="ln">142  </span></a>        <span class="s1">self._set_times(</span><span class="s4">'endTime'</span><span class="s1">, end)</span>
<a name="l143"><span class="ln">143  </span></a>
<a name="l144"><span class="ln">144  </span></a>    <span class="s2">def </span><span class="s1">_set_times(self, _id, _t)</span><span class="s3">:</span>
<a name="l145"><span class="ln">145  </span></a>        <span class="s0">&quot;&quot;&quot;&quot;&quot;&quot;</span>
<a name="l146"><span class="ln">146  </span></a>        <span class="s1">self.d.find_element_by_id(_id).click()</span>
<a name="l147"><span class="ln">147  </span></a>        <span class="s1">self.d.switch_to.default_content()</span>
<a name="l148"><span class="ln">148  </span></a>        <span class="s1">time.sleep(</span><span class="s5">1</span><span class="s1">)</span>
<a name="l149"><span class="ln">149  </span></a>        <span class="s1">self.d.switch_to.frame(self.d.find_element_by_xpath(</span><span class="s4">'//iframe[@hidefocus=&quot;true&quot;]'</span><span class="s1">))</span>
<a name="l150"><span class="ln">150  </span></a>        <span class="s1">self._set_time(_t)</span>
<a name="l151"><span class="ln">151  </span></a>
<a name="l152"><span class="ln">152  </span></a>    <span class="s2">def </span><span class="s1">_set_time(self, _t</span><span class="s3">: </span><span class="s1">str)</span><span class="s3">:</span>
<a name="l153"><span class="ln">153  </span></a>        <span class="s0">&quot;&quot;&quot;设置时间，要求焦点已经切换到框架&quot;&quot;&quot;</span>
<a name="l154"><span class="ln">154  </span></a>
<a name="l155"><span class="ln">155  </span></a>        <span class="s1">logger.debug(</span><span class="s4">'进入时间框架'</span><span class="s1">)</span>
<a name="l156"><span class="ln">156  </span></a>        <span class="s2">for </span><span class="s1">_ </span><span class="s2">in </span><span class="s1">[</span><span class="s4">'/'</span><span class="s1">, </span><span class="s4">'年'</span><span class="s1">, </span><span class="s4">'月'</span><span class="s1">, </span><span class="s4">'日'</span><span class="s1">]</span><span class="s3">:</span>
<a name="l157"><span class="ln">157  </span></a>            <span class="s1">_t </span><span class="s3">= </span><span class="s1">_t.replace(_, </span><span class="s4">'-'</span><span class="s1">)</span>
<a name="l158"><span class="ln">158  </span></a>        <span class="s1">_y, _m, _d </span><span class="s3">= </span><span class="s1">_t.split(</span><span class="s4">'-'</span><span class="s1">)</span>
<a name="l159"><span class="ln">159  </span></a>        <span class="s1">logger.debug(</span><span class="s4">f'</span><span class="s5">{</span><span class="s1">_y, _m, _d</span><span class="s5">}</span><span class="s4">'</span><span class="s1">)</span>
<a name="l160"><span class="ln">160  </span></a>
<a name="l161"><span class="ln">161  </span></a>        <span class="s1">self.d.implicitly_wait(</span><span class="s5">1</span><span class="s1">)</span>
<a name="l162"><span class="ln">162  </span></a>        <span class="s1">self.d.find_element_by_xpath(</span><span class="s4">'//*[@id=&quot;dpTitle&quot;]/div[4]/input'</span><span class="s1">).send_keys(</span><span class="s4">f'</span><span class="s5">{</span><span class="s1">Keys.BACKSPACE </span><span class="s3">* </span><span class="s5">4}{</span><span class="s1">_y</span><span class="s5">}</span><span class="s4">'</span><span class="s1">)</span>
<a name="l163"><span class="ln">163  </span></a>        <span class="s1">logger.debug(</span><span class="s4">f'设置年 - </span><span class="s5">{</span><span class="s1">_y</span><span class="s5">}</span><span class="s4">'</span><span class="s1">)</span>
<a name="l164"><span class="ln">164  </span></a>        <span class="s1">self.d.find_element_by_xpath(</span><span class="s4">'//*[@id=&quot;dpTitle&quot;]/div[3]/input'</span><span class="s1">).send_keys(</span>
<a name="l165"><span class="ln">165  </span></a>            <span class="s4">f'</span><span class="s5">{</span><span class="s1">Keys.BACKSPACE </span><span class="s3">* </span><span class="s5">2}{</span><span class="s1">int(_m)</span><span class="s5">}</span><span class="s4">'</span><span class="s1">)</span>
<a name="l166"><span class="ln">166  </span></a>        <span class="s1">self.d.execute_script(</span><span class="s4">&quot;arguments[0].click();&quot;</span><span class="s1">, self.d.find_element_by_xpath(</span><span class="s4">'//*[@id=&quot;dpTitle&quot;]/div[2]'</span><span class="s1">))</span>
<a name="l167"><span class="ln">167  </span></a>        <span class="s1">logger.debug(</span><span class="s4">f'设置月 - </span><span class="s5">{</span><span class="s1">_m</span><span class="s5">}</span><span class="s4">'</span><span class="s1">)</span>
<a name="l168"><span class="ln">168  </span></a>
<a name="l169"><span class="ln">169  </span></a>        <span class="s1">days </span><span class="s3">= </span><span class="s1">[i </span><span class="s2">for </span><span class="s1">i </span><span class="s2">in </span><span class="s1">self.d.find_elements_by_css_selector(</span><span class="s4">'table.WdayTable &gt; tbody &gt; tr &gt; td'</span><span class="s1">) </span><span class="s2">if </span><span class="s1">i.text </span><span class="s3">== </span><span class="s1">_d]</span>
<a name="l170"><span class="ln">170  </span></a>        <span class="s1">day </span><span class="s3">= </span><span class="s1">days[</span><span class="s5">0</span><span class="s1">] </span><span class="s2">if </span><span class="s1">int(_d) </span><span class="s3">&lt; </span><span class="s5">20 </span><span class="s2">else </span><span class="s1">days[</span><span class="s3">-</span><span class="s5">1</span><span class="s1">]  </span><span class="s0"># 日</span>
<a name="l171"><span class="ln">171  </span></a>        <span class="s1">ActionChains(self.d).move_to_element(day).double_click().perform()</span>
<a name="l172"><span class="ln">172  </span></a>        <span class="s1">time.sleep(</span><span class="s5">1</span><span class="s1">)</span>
<a name="l173"><span class="ln">173  </span></a>        <span class="s0">#</span>
<a name="l174"><span class="ln">174  </span></a>        <span class="s2">try</span><span class="s3">:</span>
<a name="l175"><span class="ln">175  </span></a>            <span class="s1">self.d.find_element_by_css_selector(</span><span class="s4">'table.WdayTable'</span><span class="s1">).send_keys(Keys.ENTER)</span>
<a name="l176"><span class="ln">176  </span></a>        <span class="s2">except</span><span class="s3">:</span>
<a name="l177"><span class="ln">177  </span></a>            <span class="s2">pass</span>
<a name="l178"><span class="ln">178  </span></a>        <span class="s1">self.d.switch_to.default_content()</span>
<a name="l179"><span class="ln">179  </span></a>        <span class="s1">self.d.switch_to.frame(self.iframe_add)</span>
<a name="l180"><span class="ln">180  </span></a>        <span class="s1">self.d.implicitly_wait(</span><span class="s5">6</span><span class="s1">)</span>
<a name="l181"><span class="ln">181  </span></a>
<a name="l182"><span class="ln">182  </span></a>    <span class="s2">def </span><span class="s1">set_city(self, city</span><span class="s3">=</span><span class="s4">'乌鲁木齐'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l183"><span class="ln">183  </span></a>        <span class="s0">&quot;&quot;&quot;设置城市&quot;&quot;&quot;</span>
<a name="l184"><span class="ln">184  </span></a>        <span class="s1">logger.debug(</span><span class="s4">'设置城市'</span><span class="s1">)</span>
<a name="l185"><span class="ln">185  </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'zone'</span><span class="s1">).click()</span>
<a name="l186"><span class="ln">186  </span></a>        <span class="s2">for </span><span class="s1">_clear </span><span class="s2">in </span><span class="s1">self.d.find_elements_by_css_selector(</span><span class="s4">'div#zone-option &gt; div.bbit-tree&gt; div &gt; div &gt; ul &gt; li'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l187"><span class="ln">187  </span></a>            <span class="s2">if </span><span class="s1">city </span><span class="s2">in </span><span class="s1">_clear.text</span><span class="s3">:</span>
<a name="l188"><span class="ln">188  </span></a>                <span class="s1">_clear.click()</span>
<a name="l189"><span class="ln">189  </span></a>                <span class="s2">return </span><span class="s1">self.d</span>
<a name="l190"><span class="ln">190  </span></a>
<a name="l191"><span class="ln">191  </span></a>    <span class="s2">def </span><span class="s1">set_contact(self, contact</span><span class="s3">=</span><span class="s4">'李老板LeeCQ'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l192"><span class="ln">192  </span></a>        <span class="s0">&quot;&quot;&quot;设置联系人&quot;&quot;&quot;</span>
<a name="l193"><span class="ln">193  </span></a>        <span class="s1">logger.debug(</span><span class="s4">'设置联系人'</span><span class="s1">)</span>
<a name="l194"><span class="ln">194  </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'contactperson'</span><span class="s1">).send_keys(contact)</span>
<a name="l195"><span class="ln">195  </span></a>        <span class="s2">return </span><span class="s1">self.d</span>
<a name="l196"><span class="ln">196  </span></a>
<a name="l197"><span class="ln">197  </span></a>    <span class="s2">def </span><span class="s1">set_addr(self, addr</span><span class="s3">=</span><span class="s4">'陕西省汉中市南郑区'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l198"><span class="ln">198  </span></a>        <span class="s0">&quot;&quot;&quot;设置地址&quot;&quot;&quot;</span>
<a name="l199"><span class="ln">199  </span></a>        <span class="s1">logger.debug(</span><span class="s4">'正在设置发货地址'</span><span class="s1">)</span>
<a name="l200"><span class="ln">200  </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'address'</span><span class="s1">).send_keys(addr)</span>
<a name="l201"><span class="ln">201  </span></a>        <span class="s1">time.sleep(</span><span class="s5">1</span><span class="s1">)</span>
<a name="l202"><span class="ln">202  </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'address'</span><span class="s1">).send_keys(Keys.DOWN)</span>
<a name="l203"><span class="ln">203  </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'address'</span><span class="s1">).send_keys(Keys.ENTER)</span>
<a name="l204"><span class="ln">204  </span></a>        <span class="s2">return </span><span class="s1">self.d</span>
<a name="l205"><span class="ln">205  </span></a>
<a name="l206"><span class="ln">206  </span></a>    <span class="s2">def </span><span class="s1">set_detailed_addr(self, addr</span><span class="s3">=</span><span class="s4">'detailedAddress'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l207"><span class="ln">207  </span></a>        <span class="s0">&quot;&quot;&quot;设置详细地址&quot;&quot;&quot;</span>
<a name="l208"><span class="ln">208  </span></a>        <span class="s1">logger.debug(</span><span class="s4">'设置详细地址'</span><span class="s1">)</span>
<a name="l209"><span class="ln">209  </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'detailedAddress'</span><span class="s1">).send_keys(addr)</span>
<a name="l210"><span class="ln">210  </span></a>
<a name="l211"><span class="ln">211  </span></a>    <span class="s2">def </span><span class="s1">set_phone_num(self, num</span><span class="s3">=</span><span class="s4">'17700001111'</span><span class="s1">)</span><span class="s3">:</span>
<a name="l212"><span class="ln">212  </span></a>        <span class="s0">&quot;&quot;&quot;设置电话号码&quot;&quot;&quot;</span>
<a name="l213"><span class="ln">213  </span></a>        <span class="s1">logger.debug(</span><span class="s4">'设置电话号码'</span><span class="s1">)</span>
<a name="l214"><span class="ln">214  </span></a>        <span class="s1">self.d.find_element_by_id(</span><span class="s4">'iphone'</span><span class="s1">).send_keys(num)</span>
<a name="l215"><span class="ln">215  </span></a>        <span class="s2">return </span><span class="s1">self.d</span>
<a name="l216"><span class="ln">216  </span></a>
<a name="l217"><span class="ln">217  </span></a>    <span class="s2">def </span><span class="s1">ok(self)</span><span class="s3">:</span>
<a name="l218"><span class="ln">218  </span></a>        <span class="s0">&quot;&quot;&quot;确定&quot;&quot;&quot;</span>
<a name="l219"><span class="ln">219  </span></a>        <span class="s1">logger.debug(</span><span class="s4">'焦点切换到默认框架'</span><span class="s1">)</span>
<a name="l220"><span class="ln">220  </span></a>        <span class="s1">self.d.switch_to.default_content()</span>
<a name="l221"><span class="ln">221  </span></a>        <span class="s1">time.sleep(</span><span class="s5">0.5</span><span class="s1">)</span>
<a name="l222"><span class="ln">222  </span></a>        <span class="s0"># #layui-layer1 &gt; div.layui-layer-btn &gt; a.layui-layer-btn0</span>
<a name="l223"><span class="ln">223  </span></a>        <span class="s1">self.d.find_element_by_css_selector(</span><span class="s4">'#layui-layer1 &gt; div.layui-layer-btn &gt; a.layui-layer-btn0'</span><span class="s1">).click()</span>
<a name="l224"><span class="ln">224  </span></a>        <span class="s1">logger.info(</span><span class="s4">'提交客户档案成功！'</span><span class="s1">)</span>
<a name="l225"><span class="ln">225  </span></a>
<a name="l226"><span class="ln">226  </span></a>
<a name="l227"><span class="ln">227  </span></a><span class="s2">if </span><span class="s1">__name__ </span><span class="s3">== </span><span class="s4">'__main__'</span><span class="s3">:</span>
<a name="l228"><span class="ln">228  </span></a>    <span class="s1">logger.addHandler(console_handler)</span>
<a name="l229"><span class="ln">229  </span></a>    <span class="s1">unittest.main()</span>
<a name="l230"><span class="ln">230  </span></a>    <span class="s0"># AddCustomer(login_easy('test', '123456'), 'test_03', 'test_03')</span>
<a name="l231"><span class="ln">231  </span></a></pre>
</body>
</html>